package com.sk.ccflower.lib.sockUtils.packet;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class PacketDataUnit {
	
	public DataHeader header;
	public ByteBuffer body;
	
	public PacketDataUnit() {
		header = null;
		body = null;
	}
	
	public void CopyHeader( DataHeader _header ) {
		if ( header == null )
			header = new DataHeader();
		
		header.version = _header.version;
		header.type = _header.type;
		header.status = _header.status;
		header.pad = _header.pad;
		header.mid = _header.mid;
		header.uid = _header.uid;
		header.seq = _header.seq;
		header.len = _header.len;
		header.ts = _header.ts;
		header.spare1 = _header.spare1;
		header.spare2 = _header.spare2;
		header.domain1 = _header.domain1;
		header.domain2 = _header.domain2;
		header.node1 = _header.node1;
		header.node2 = _header.node2;
	}
	
	public void CopyBuffer( ByteBuffer buffer ) {
		buffer.flip();
		if ( body == null ) {
			body = ByteBuffer.allocate( buffer.remaining() );
			body.order( ByteOrder.BIG_ENDIAN );
		}
		
		body.put( buffer.array(), 0, buffer.remaining() );
	}
	
}
